// $Id$
// Licensed under Apache License Version 2.0
// See: http://www.apache.org/licenses/LICENSE-2.0.html
package de.servicezombie.errors.sample;

import de.servicezombie.errors.ErrorMessage;

public class Main {

	/**
	 * testprogramm to show output of objects
	 */
	public static void main(String[] args) {

		/* build sample example data */
		NestedInput root = new NestedInput(1);
		NestedInput leaf = addSomeChildrenAndReturnLeaf(root);

		dumpObject("root", root); // least specific id. NestedInput$1
		dumpObject("leaf", leaf); // most specific id: NestedInput$1.NestedInput.NestedInput$3.NestedInput.NestedInput$5

		/* we create a error message with a source attribute */
		ErrorMessage error = new ErrorMessage("any-key", 1, 2, 3, 4).attachSource(leaf);
		dumpObject("an error-message goes to view components\n\t", error);

	}

	private static NestedInput addSomeChildrenAndReturnLeaf(NestedInput root) {
		NestedInput child1 = new NestedInput(null);
		NestedInput child2 = new NestedInput(3);
		NestedInput child3 = new NestedInput(null);
		NestedInput leaf = new NestedInput(5);

		leaf.setParent(child3);
		child3.setParent(child2);
		child2.setParent(child1);
		child1.setParent(root);
		return leaf;
	}

	private static void dumpObject(String name, Object leaf) {
		System.out.println(name + ": " + leaf);
	}

}
